<template>
    <div>
        <div v-if="currentPanel == 'list'">
            <el-card class="box-card">
                <el-button type="primary" @click="currentHandle('add')" size="small">+新建群发</el-button>
                <div class="interspaceH"></div>
                <el-table :data="dataSource" style="width: 100%"
                          :header-cell-style="{background:'#F3F4F7',color:'#555'}">
                    <el-table-column prop="missionName" label="群发内容" :formatter="formatter"></el-table-column>
                    <el-table-column prop="empName" label="执行人" :formatter="formatter"></el-table-column>
                    <el-table-column prop="finishTime" label="发送时间" :formatter="formatter"></el-table-column>
                    <el-table-column prop="missionStatus" label="发送状态" :formatter="formatter"></el-table-column>
                    <el-table-column prop="createTime" label="群发创建时间"></el-table-column>
                    <el-table-column label="操作">
                        <template slot-scope="scope">
                            <el-button type="text" size="small" @click="alertSendHandle(scope.row)">提醒发送</el-button>
<!--                            <el-divider direction="vertical"></el-divider>
                            <el-button @click="detailHandle(scope.row)" type="text" size="small">详情</el-button>-->
                        </template>
                    </el-table-column>
                </el-table>

                <div class="interspaceH"></div>

                <el-pagination @size-change="queryDataHandle(pagePagination.currentPage,$event)"
                               @current-change="queryDataHandle($event,pagePagination.pageSize)"
                               :current-page="pagePagination.currentPage"
                               :page-sizes="pagePagination.pageSizes" :page-size="pagePagination.pageSize"
                               layout="total, sizes, prev, pager, next"
                               :total="pagePagination.total">
                </el-pagination>
            </el-card>
        </div>

        <div v-if="currentPanel == 'add'">
            <CreatMassText @currentHandle="currentHandle"/>
        </div>
        <div v-if="currentPanel == 'detail'">
            <Detail @currentHandle="currentHandle" :missionInfo="missionInfo"/>
        </div>
    </div>
</template>

<script>
import CreatMassText from "@/views/customer/client_mass_text/add"
import Detail from "@/views/customer/client_mass_text/detail"
//多选框 - 开始
const sendType = [
    {
        value: '1',
        label: '立即发送'
    },
    {
        value: '2',
        label: '定时发送'
    }
]

const sendState = [
    {
        value: '1',
        label: '已发送'
    },
    {
        value: '2',
        label: '未发送'
    }
]
//多选框 - 结束

export default {
    components: {
        CreatMassText,
        Detail
    },
    data() {
        return {
            currentPanel: 'list',
            tablePage: 0,
            dictionary: {
                sendType: sendType,
                sendState: sendState,
            },
            fieldType: {
                sendType: "array",
                sendState: "array",
                finishTime: "datetime",
                createTime: "datetime"
            },
            dataSource: [],
            pagePagination: {
                currentPage: 1,
                pageSizes: [10, 15, 20, 25],
                pageSize: 10,
                total: 0
            },
            missionInfo: {}
        }
    },
    mounted() {
        this.queryDataHandle()
    },
    methods: {
        currentHandle(e) {
            this.currentPanel = e
            if (e == 'list') {
                this.queryDataHandle()
            }
        },
        queryDataHandle(page = 1, row = 10) {
            let that = this;
            let payload = {
                pageNum: page,
                pageSize: row,
                taskCorrelationType: '8'
            }
            that.$request("/api/task/getTaskList/1_0", payload, "POST").then((data) => {
                that.dataSource = data.rows
                that.pagePagination['total'] = data.total
                that.pagePagination['pageSize'] = data.row
            });
        },
        alertSendHandle(data) {
            let requestBody = {
                touser: data.sendEmpId,
                msgtype: "text",
                text: {content: "请处理群发任务"}
            }

            this.$request("/api/wechat/sendMessageForApp", {requestJson:JSON.stringify(requestBody)}, "POST").then((data) => {
                this.$message.success("提醒成功")
            });
        },
        formatter(row, column) {
            let field = column.property;
            let value = row[field];
            return this.$utils.formatterForLable(field, value, this.fieldType, this['dictionary'][field]);
        },
        detailHandle(row) {
            this.missionInfo = this.$utils.formatterForForm(row, this.fieldType, this.dictionary);
            this.currentHandle('detail')
        }
    }
}
</script>

<style scoped>
</style>
